package com.dm.shop.mapper;

import com.dm.shop.entity.OrderList;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author MyBatisPlusGenerater-Saiya Wang
 * @since 2021-07-20
 */
@Mapper
@Repository
public interface OrderListMapper extends BaseMapper<OrderList> {
    @Select("SELECT order_list.id as id, product.store as store," +
            "order_list.amount as amount,product.`name` as name," +
            "order_list.create_time as create_time, product_image.img_url as img_url, " +
            "order_detail.number as number " +
            "from order_list, order_detail, user, product, product_image where order_list.uid = #{uid} and order_list.id = order_detail.oid and order_list.uid = user.id and order_detail.pid = product.id and product.id = product_image.pid group by product_image.pid;")
    List<Map> getOrderListInfoByUid(int uid);

    @Select("SELECT order_list.id as id,order_list.amount as amount, " +
            "order_list.`status` as status,order_list.create_time as create_time, " +
            "order_list.user_message as user_message,order_list.update_time as update_time, " +
            "order_list.uid as uid,user.user_name as user_name,  " +
            "user.phone_number as phone_number,address.area as area, " +
            "address.receiver as receiver,address.street as street " +
            "from order_list, user, address where order_list.uid = user.id and order_list.aid = address.id;")
    List<Map> getAllOrderInfo();

    @Select("select product.*,order_detail.number as number from product, order_list, order_detail where order_list.id = #{id} and order_list.id = order_detail.oid and order_detail.pid = product.id;")
    List<Map> getProductInfoById(int id);
}
